//
//  MTInterestViewController.m
//  MotorTravel
//
//  Created by zk on 16/9/12.
//  Copyright © 2016年 zk. All rights reserved.
//

#import "MTInterestViewController.h"
#import "MTInterestCollectionViewCell.h"
#import "MTAllOrEssenceTableViewCell.h"
#import "MTInterestLeftTableViewCell.h"
#import "MTInterestRightTableViewCell.h"

@interface MTInterestViewController ()
<
UICollectionViewDelegate,
UICollectionViewDataSource,
UICollectionViewDelegateFlowLayout,
UITableViewDelegate,
UITableViewDataSource
>

@property (weak, nonatomic) IBOutlet UITableView *allOrEssenceTableView;///<看精华或者全部
@property (weak, nonatomic) IBOutlet UITableView *interestLeftTableView;///<兴趣分类
@property (weak, nonatomic) IBOutlet UITableView *interestRightTableView;///<兴趣种类
@property (weak, nonatomic) IBOutlet UISegmentedControl *segmengtedControl;///<兴趣
@property (weak, nonatomic) IBOutlet UICollectionView *collectionVIew;
@property (nonatomic, strong) NSMutableArray *interestArray;
@property (nonatomic, strong) NSMutableArray *leftArray;
@property (nonatomic, strong) NSMutableArray *rightArray;


@end

@implementation MTInterestViewController

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadBaseUI];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadBaseUI {
    self.segmengtedControl.selectedSegmentIndex = 0;
    //segmentedcontrol 选中的文字颜色
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil];
    [self.segmengtedControl setTitleTextAttributes:dic forState:UIControlStateSelected];
    //collectionview
    self.collectionVIew.delegate = self;
    self.collectionVIew.dataSource = self;
    //tableview
    self.allOrEssenceTableView.delegate = self;
    self.allOrEssenceTableView.dataSource = self;
    self.allOrEssenceTableView.tableFooterView = [UIView new];
    
    self.interestLeftTableView.delegate = self;
    self.interestLeftTableView.dataSource = self;
    self.interestLeftTableView.tableFooterView = [UIView new];
    
    self.interestRightTableView.delegate = self;
    self.interestRightTableView.dataSource = self;
    self.interestRightTableView.tableFooterView = [UIView new];
}

#pragma mark - collectionview datasource 

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.interestArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MTInterestCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MTInterestCollectionViewCell" forIndexPath:indexPath];
    return cell;
}

#pragma mark - collectionview flowlayout

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat width = [UIScreen mainScreen].bounds.size.width / 2 - 18;
    return CGSizeMake(width, width * 412 / 341);
}

#pragma mark - tableview datasource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView == self.allOrEssenceTableView) {
        return 2;
    } else if (tableView == self.interestLeftTableView) {
        return self.leftArray.count;
    } else {
        return self.rightArray.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.allOrEssenceTableView) {
        MTAllOrEssenceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MTAllOrEssenceTableViewCell"];
        return cell;
    } else if (tableView == self.interestLeftTableView) {
        MTInterestLeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MTInterestLeftTableViewCell"];
        return cell;
    } else {
        MTInterestRightTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MTInterestRightTableViewCell"];
        return cell;
    }
}

#pragma mark - Setter & Getter

- (NSMutableArray *)interestArray {
    if (!_interestArray) {
        _interestArray = [[NSMutableArray alloc] init];
    }
    return _interestArray;
}

- (NSMutableArray *)leftArray {
    if (!_leftArray) {
        _leftArray = [[NSMutableArray alloc] init];
    }
    return _leftArray;
}

- (NSMutableArray *)rightArray {
    if (!_rightArray) {
        _rightArray = [[NSMutableArray alloc] init];
    }
    return _rightArray;
}

@end
